package com.logistics.command.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.logistics.command.model.CarryingModel;
import com.logistics.command.model.DeliveryModel;
import com.logistics.command.model.PlaceModel;
import com.logistics.command.service.CommandService;
import com.logistics.utils.exception.MessageException;
import com.logistics.utils.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("lgs/command")
public class CommandController {

    @Autowired
    private CommandService commandService;

    /**
     * 托盘搭载
     * @param model
     * @return
     * @throws JsonProcessingException
     */
    @PutMapping("carrying")
    public ResponseEntity carrying(@RequestBody CarryingModel model) throws JsonProcessingException, MessageException {
        commandService.carrying(model);
        return ResponseUtil.success();
    }

    /**
     * 托盘放置
     * @param model
     * @return
     * @throws JsonProcessingException
     */
    @PutMapping("place")
    public ResponseEntity place(@RequestBody PlaceModel model) throws JsonProcessingException, MessageException {
        commandService.place(model);
        return ResponseUtil.success();
    }

    /**
     * 配送任务
     * @param model
     * @return
     * @throws JsonProcessingException
     * @throws MessageException
     */
    @PutMapping("delivery")
    public ResponseEntity delivery(@RequestBody DeliveryModel model) throws JsonProcessingException, MessageException {
        commandService.delivery(model);
        return ResponseUtil.success();
    }

}
